package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"sync"
)

var rdb *redis.Client

func WitRedis(head func(rdb *redis.Client)) {
	var once sync.Once
	var err error
	once.Do(func() {
		client := redis.NewClient(&redis.Options{
			Addr:     "121.36.228.151:6379",
			Password: "", // no password set
			DB:       0,  // use default DB
		})
		_, err = client.Ping().Result()
	})
	if err != nil {
		fmt.Println("缓存链接失败", err)
		panic(err)
	}
	head(rdb)
	fmt.Println("redis 链接成功")
	// Output: PONG <nil>
}
